var wxb=wxb||{};
JsRouter.map([
    {
        path:'/index',//路由路径
        join:'wxb.index.i',//进入此路由执行
        back:'wxb.index.i'//退回此路由执行
    },
    {
        'path':'/dynamicDesc',
        'join':'wxb.dynamicDesc.i',
        'back':'wxb.dynamicDesc.i'
    },
    {
        path:'/information',
        join:'wxb.information.i',
        back:'wxb.information.i'
    },
    {
        path:'/informationDesc',
        join:'wxb.informationDesc.i',
        back:'wxb.informationDesc.i'
    },
    {
        path:'/add',
        join:'wxb.add.i',
        back:'wxb.add.i'
    },
    {
        path:'/changeAdd',
        join:'wxb.changeAdd.i',
        back:'wxb.changeAdd.i'
    },
    {
        path:'/topic',
        join:'wxb.topic.i',
        back:'wxb.topic.i'
    },
    {
        path:'/report',
        join:'wxb.report.i',
        back:'wxb.report.i'
    },
    {
        'path':'/reportAdd',
        'join':'wxb.reportAdd.i',
        'back':'wxb.reportAdd.i'
    },
    {
        'path':'/reportDesc',
        'join':'wxb.reportDesc.i',
        'back':'wxb.reportDesc.i'
    },
    {
        'path':'/eventManage',
        'join':'wxb.eventManage.i',
        'back':'wxb.eventManage.i'
    },
    {
        'path':'/riskManage',
        'join':'wxb.riskManage.i',
        'back':'wxb.riskManage.i'
    },
    {
        'path':'/todayDesc',
        'join':'wxb.todayDesc.i',
        'back':'wxb.todayDesc.i'
    },
    {
        'path':"/eventRiskDesc",
        'join':'wxb.eventRiskDesc.i',
        'back':'wxb.eventRiskDesc.i'
    },
    {
        'path':'/task',
        'join':'wxb.task.i',
        'back':'wxb.task.i'
    },
    {
        'path':'/taskDesc',
        'join':'wxb.taskDesc.i',
        'back':'wxb.taskDesc.i'
    },
    {
        'path':'/placeAdd',
        'join':'wxb.placeAdd.i',
        'back':'wxb.placeAdd.i'
    },
    {
        'path':'/snapshot',
        'join':'wxb.snapshot.i',
        'back':'wxb.snapshot.i'
    }
]);
JsRouter.render();
wxb.init={
    e:{
        $:'',
        userID:'',
        role:''//用户角色 1值班员,2领导,3地方网信办,4运营单位
    },
    com:{
        isOk:function(c){
            var poll=function(){
                if(!wxb.init.e.$){
                    setTimeout(poll,20)
                }else{
                    if(wxb.init.e.role){
                        c?c():'';
                    }else{
                        setTimeout(poll,20)
                    }
                }
            };
            poll();
        },
        toggle:function(e,className){
            var $=wxb.init.e.$;
            if($(e).hasClass(className)){
                $(e).removeClass(className)
            }else{
                $(e).addClass(className)
            }
        },
        menu:function(m){
            var nd={id:wxb.init.e.role.id,menu:m};
            JsTpl('.aside-menu').render(nd,'menu');
            wxb.init.e.$('.aside-menu [data-menu="'+m+'"]').addClass('active').siblings().removeClass('active');
        }
    },
    load:function(){
        var _t=this;
        fui.use(['JsPage','JsTpl','JsForm','layer','jeDate'],function(){
            wxb.init.e.$=fui.$;
            _t.btn.i();
            wxbData.role(function(r){
                wxb.init.e.role=r;
                JsTpl('.header').render(wxb.init.e.userInfo,'header');
                JsForm().skin();
            });
        });
    },
    btn:{
        i:function(){
           var $=wxb.init.e.$,body=$('body'),header=$('.header');
            header.hover(function(){
                header.addClass('hover')
            },function(){
                $('.header-user').removeClass('active');
                header.removeClass('hover')
            });
            body.on('click',function(){
                $('.header-user').removeClass('active');
           });
            //tab
            body.on('click','[data-click="tab"]',function(){
                var _t=$(this),tn=_t.data('tab');
                _t.addClass('active').siblings().removeClass('active');
                $('[data-tcon="'+tn+'"]').show().siblings().hide();
            });
            //全选
            body.on('click','.checkAll',function(){
                var _t=$(this),ta=$('[data-checkbox="'+_t.data('cbt')+'"]');
               if(_t.is(':checked')){
                   ta.find('.checkR').prop('checked',true);
               }else{
                   ta.find('.checkR').prop('checked',false);
               }
            });
            body.on('click','.checkR',function(){
                var _t=$(this),ta=_t.parents('.mesList-wrap'),ak=$('.checkAll[data-cbt="'+ta.data('checkbox')+'"]');
                if(_t.is(':checked')){
                    if(ta.find('.checkR:checked').length==ta.find('.checkR').length){
                        ak.prop('checked',true);
                    }
                }else{
                    ak.prop('checked',false);
                }
            });

            wxb.reportAdd.btn.toCheck();
            wxb.orgFun.btn();
            this.resize();
        },
        userShow:function(){
           fui.stope();
           wxb.init.e.$('.header-user').addClass('active');
       },
        resize:function(){
            wxb.init.e.$(window).resize(function() {
                wxb.index.size();
            });
        },
        back:function(){
            if(JsRouter.way.length==1){//没有后退的
                location.hash=wxb.init.e.$('.aside-menu .active a').attr('href')
            }else{//后退
                history.back()
            }
        }
    },
    textarea:function(name){
        var editor=KindEditor.create('.form-item-textarea[name="'+name+'"]',{
            resizeType : 1,
            allowPreviewEmoticons : false,
            allowImageUpload : false,
            items : [
                'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                'insertunorderedlist', '|', 'link'],
            afterBlur: function(){this.sync();}
        });
        return editor;
    }
};

wxb.init.load();

//首页
wxb.index={
    i:function(){
        wxb.init.com.isOk(function(){
            switch (wxb.init.e.role.roleRank){
                case 1://领导
                case "1"://领导
                case 2://值班员
                case "2"://值班员
                case 3://地方
                case "3"://地方
                case 4://运营
                case "4"://运营
                case 5://安全厂商
                case "5"://安全厂商
                case 6://专家
                case "6"://专家
                    wxb.index.load(wxb.init.e.role.roleRank);
                    break;
                default:
                    layer.msg('未定义角色');
                    break;
            }
        });
    },
    com:{
        toList:function(){
            var d={page:1};
            wxbData.dynamic(d,function(r){
                dyList(r,r['current']);
                JsPage('[data-page="home"]').render(r['total'],r['current'],function(ck){
                    d.page=ck;
                    wxbData.dynamic(d,function(cr){
                        dyList(cr,ck);
                    })
                });
            });
            var dyList=function(dr,page){//数据填充
                JsTpl('.safeDy-list').render(dr,'dynamicItem',page);
            }
        },
        toNum:function(mr){
            wxbData.dataCount(function(r){
                JsTpl('.hr-yjTj').render(r,'yjCount');
                JsTpl('.hr-sjTj').render(r,'sjCount');
                if(mr==1||mr==2){
                    JsTpl('.hr-rwMb').render(r,'rwMb');
                }
            });
        }
    },
    load:function(r){//数据加载
        wxb.init.com.menu('index');
        var nr={myRole:r};
        JsTpl('.mod-main').render(nr,'home');
        wxb.index.size();
        wxb.index.com.toList();
        wxb.index.com.toNum(r);
    },
    size:function(){
        var $=wxb.init.e.$;
        var wh=$(window).height();
        wh=wh-5>710?wh-5:710;
        wxb.init.e.$('.main-box').css('height',wh);
        $('.hr-box').css('padding-bottom',(wh-710)/3);
    },
    btn:{
        toDynamicDesc:function(id){
            location.hash='/dynamicDesc?id='+id
        },
        toSnapshot:function(type,level){
            location.hash='/snapshot?type='+type+'&level='+level
        }
    }
};

//信息中心
wxb.information={
    d:{
        dclXx:{},//待处理信息
        hasCheckNum:0,
        xtJson:{
            ids:[],
            list:[]
        },//选题JSON
        letterSx:{},//今日快报
        historySx:{}//历史信息
    },
    reset:function(r,t,s){//重置筛选条件
        var wd=wxb.information.d;
        switch (r){
            case 2://待处理条件
                wd['dclXx']={
                    page:1,//分页
                    type:t,//类型：1信息,2风险,3事件
                    startTime:'',//开始时间
                    endTime:'',//结束时间
                    title:''//标题
                };
                break;
            case 3:
                wd['letterSx']={
                    page:1,
                    type:t,//0在办,1办结
                    startTime:'',
                    endTime:'',
                    title:'',
                    userID:wxb.init.e.userID
                };
                break;
            case 4:
                wd['historySx']={
                    page:1,
                    type:t,//1信息,2风险,3事件
                    startTime:'',
                    endTime:'',
                    title:'',
                    isEnabled:s//2已处理,3待采用
                };
                break;
        }
    },
    i:function(r){
        wxb.init.com.isOk(function(){
            switch (wxb.init.e.role.roleRank){
                case 1://领导
                case "1"://领导
                    wxb.information.load();
                    break;
                case 2://值班员
                case "2"://值班员
                    wxb.information.load2(r);
                    break;
                default://其他角色进来时
                    location.hash='/index';
                    break;
            }
        });
    },
    com:{
        time:function(box,data,fun){
            var start={
                format:'YYYY-MM-DD',
                maxDate:$.nowDate({DD:"0"}),
                okfun:function(v){
                    end.minDate =v.val;
                    wxb.information.d[data]['startTime']=v.val;
                    wxb.information.com[fun].call(this);
                    endDates();
                },
                clearfun:function(){
                    wxb.information.d[data]['startTime']='';
                    wxb.information.com[fun].call(this);
                }
            };
            var end={
                format:'YYYY-MM-DD',
                maxDate:$.nowDate({DD:"0"}),
                okfun:function(v){
                    start.maxDate=v.val;
                    wxb.information.d[data]['endTime']=v.val;
                    wxb.information.com[fun].call(this);
                },
                clearfun:function(){
                    wxb.information.d[data]['endTime']='';
                    wxb.information.com[fun].call(this);
                }
            };
            function endDates() {
                end.trigger = false;
                $.jeDate('#'+box+'_end',end);
            }
            $.jeDate('#'+box+'_start',start);
            $.jeDate('#'+box+'_end',end);
        },
        zbyDcl:function(){//值班员待处理
            var d=wxb.information.d.dclXx;
            wxbData.dclList(d,function(r){
                dclData(r,r['current']);
                //分页初始化
                JsPage('.ib-page[data-page="ift0"]').render(r['total'],r['current'],function(ck){
                    d.page=ck;
                    wxbData.dclList(d,function(cr){
                        dclData(cr,ck);
                    })
                });
            });
            var dclData=function(dr,page){//数据填充
                JsTpl('[data-list="dcl"]').render(dr,'list-item-'+d.type,page);
                wxb.init.e.$.each(wxb.information.d.xtJson['ids'],function(m,n){
                    wxb.init.e.$('[data-list="dcl"]').find('.item[data-id="'+n+'"]').addClass('disabled').find('.checkR').prop('checked',true);
                });
            }
        },
        letterList:function(){
            var d=wxb.information.d.letterSx;
            wxbData.todayBulletin(d,function(r){
                letterData(r,r['current']);
                JsPage('.ib-page[data-page="ift1"]').render(r['total'],r['current'],function(ck){
                    d.page=ck;
                    wxbData.todayBulletin(d,function(cr){
                        letterData(cr,ck);
                    })
                });
            });
            var letterData=function(dr,page){
                dr.myUserID=wxb.init.e.userID;
                dr.myRole=wxb.init.e.role.roleRank;
                JsTpl('[data-list="letter"]').render(dr,'list-letter-'+d.type,page);
            }
        },
        historyList:function(){
            var d=wxb.information.d.historySx;
            wxbData.historyList(d,function(r){
                historyData(r,r['current']);
                JsPage('.ib-page[data-page="ift2"]').render(r['total'],r['current'],function(ck){
                    d.page=ck;
                    wxbData.historyList(d,function(cr){
                        historyData(cr,ck);
                    })
                });
            });
            var historyData=function(dr,page){
                JsTpl('[data-list="history"]').render(dr,'list-history-'+d.type,page);
            }
        }
    },
    load:function(){//数据加载
        wxb.init.com.menu('information');
        var $=wxb.init.e.$;
        JsTpl('.mod-main').render({tabNav:2},'information');
        $('.article-bd').empty().append($('#information-item-'+2).html());
        $('.btn-info-letter').eq(0).click();
        wxb.information.com.time('letter','letterSx','letterList');
    },
    load2:function(r){
        wxb.init.com.menu('information');
        var $=wxb.init.e.$;
        var tabNav=r['tabNav']||1;
        JsTpl('.mod-main').render({tabNav:tabNav},'information2');
        $('.article-bd').empty().append($('#information-item-'+tabNav).html());
        switch (tabNav){
            case 1:
            case '1':
                var tt=wxb.information.d.tabType||1;
                $('.btn-info-type').eq(parseInt(tt)-1).click();
                break;
            case 2:
            case '2':
                //今日快报
                $('.btn-info-letter').eq(0).click();
                wxb.information.com.time('letter','letterSx','letterList');
                break;
            case 3:
            case '3':
                //历史信息
                wxb.information.reset(4,1,1);
                $('.btn-info-history').eq(0).click();
                wxb.information.com.time('history','historySx','historyList');
                break;
        }
        wxbData.hasDclNum(function(n){
            if(n!=0){
                var nh='<span class="navTopRight hasToDealNum">'+n+'</span>';
                wxb.init.e.$('.information-tab a').eq('0').append(nh);//待处理信息
            }
        });
    },
    btn:{
        tabType:function(t,tt){
            var $=wxb.init.e.$,_t=$(t);
            if(!_t.hasClass('active')){
                wxb.information.d.tabType=tt;
                _t.addClass('active').siblings().removeClass('active');
                var nd={type:tt};
                JsTpl('.form-type-box').render(nd,'type-box');
                wxb.information.reset(2,tt);
                wxb.information.com.zbyDcl();
                wxb.information.com.time('zby','dclXx','zbyDcl');
                var xt=sessionStorage.getItem('zbyXt');
                if(xt){
                    wxb.information.d.xtJson=JSON.parse(xt);
                }
                wxb.information.d.hasCheckNum=wxb.information.d.xtJson['ids'].length;
                $('.hasCheckNum').text(wxb.information.d.hasCheckNum)
            }
        },
        keydown:function(e,t){//标题搜索
            var $=wxb.init.e.$,_t=$(t);
            if(e.keyCode==13){
                wxb.information.d.dclXx['title']=_t.val();
                wxb.information.com.zbyDcl();
            }
        },
        toAdd:function(t,json){
            var $=wxb.init.e.$,_t=$(t),ta=_t.parents('.item');
            ta.addClass('disabled').find('.checkR').prop('checked',true);
            wxb.information.d.hasCheckNum++;
            wxb.information.d.xtJson['ids'].push(ta.data('id'));
            wxb.information.d.xtJson['list'].push(json);
            sessionStorage.setItem('zbyXt',JSON.stringify(wxb.information.d.xtJson));
            $('.hasCheckNum').text(wxb.information.d.hasCheckNum);
        },
        toAllAdd:function(){
            var $=wxb.init.e.$;
            // wxb.information.d.hasCheckNum=0;
            // wxb.information.d.xtJson['list']=[];
            // wxb.information.d.xtJson['ids']=[];
            $.each($('[data-list="dcl"]').find('.checkR:checked'),function(m,n){
                var ta=$(n).parents('.item');
                if(wxb.information.d.xtJson['ids'].indexOf(ta.data('id'))==-1){
                    ta.find('.btn-add-xt').click();
                }
            });
        },
        toNoUse:function(){
            var $=wxb.init.e.$,ids=[];
            $.each($('[data-list="dcl"]').find('.checkR:checked'),function(m,n){
                var ta=$(n).parents('.item');
                if(!ta.hasClass('disabled')){
                    ids.push(ta.data('id'));
                }
            });
            if(ids.length>0){
                wxbData.noUse(ids,function(){
                    layer.msg('操作成功');
                    wxb.information.com.zbyDcl();//拉取新数据
                    wxbData.hasDclNum(function(n){
                        if(n!=0){
                            var nh='<span class="navTopRight hasToDealNum">'+n+'</span>';
                            wxb.init.e.$('.information-tab a').eq('0').append(nh);//待处理信息
                        }
                    });
                });
            }
        },
        topic:function(){
            if(wxb.information.d.xtJson['ids'].length!=0){
                location.hash='/topic'
            }
        },
        desc:function(type,id,state){
            var url='/informationDesc?type='+type+'&id='+id;
            state?(url+='&state='+state):"";
            location.hash=url
        },
        toChange:function(fromType,type,id){
            location.hash='/changeAdd?type='+type+'&id='+id+'&fromType='+fromType;
        },
        //今日快报
        tabType2:function(t,tt){
            var $=wxb.init.e.$,_t=$(t);
            if(!_t.hasClass('active')){
                _t.addClass('active').siblings().removeClass('active');
                wxb.information.reset(3,tt);
                wxb.information.com.letterList();
            }
        },
        keydown2:function(e,t){//标题搜索
            var $=wxb.init.e.$,_t=$(t);
            if(e.keyCode==13){
                wxb.information.d.letterSx['title']=_t.val();
                wxb.information.com.letterList();
            }
        },
        todayDesc:function(id){
            location.hash='/todayDesc?id='+id;
        },
        //历史信息
        tabType3:function(t,tt){//状态
            var $=wxb.init.e.$,_t=$(t);
            if(!_t.hasClass('active')){
                _t.addClass('active').siblings().removeClass('active');
                wxb.information.d.historySx['isEnabled']=tt;
                $('.btn-info-history1').eq(0).removeClass('active').click();
            }
        },
        tabType31:function(t,tt){//类型
            var $=wxb.init.e.$,_t=$(t);
            if(!_t.hasClass('active')){
                _t.addClass('active').siblings().removeClass('active');
                wxb.information.d.historySx['type']=tt;
                wxb.information.com.historyList();
            }
        },
        keydown3:function(e,t){//标题搜索
            var $=wxb.init.e.$,_t=$(t);
            if(e.keyCode==13){
                wxb.information.d.historySx['title']=_t.val();
                wxb.information.com.historyList();
            }
        },
        reUse:function(id,isList){
            wxbData.reUse(id,function(){
                wxbData.hasDclNum(function(n){
                    if(n!=0){
                        var nh='<span class="navTopRight hasToDealNum">'+n+'</span>';
                        wxb.init.e.$('.information-tab a').eq('0').append(nh);//待处理信息
                    }
                });
                if(isList){//列表页面
                    wxb.information.com.historyList();
                }else{//详情页面
                    history.back();
                }
            });
        }
    }
};
//--信息详情
wxb.informationDesc={
    i:function(r){
        wxb.init.com.isOk(function(){
            wxb.informationDesc.load(r);
        })
    },
    load:function(r){
        if(!r) return history.back();
        wxb.init.com.menu('information');
        var xt=sessionStorage.getItem('zbyXt');
        if(xt){
            wxb.information.d.xtJson=JSON.parse(xt);
        }
        var $=wxb.init.e.$;
        $('.mod-main').empty().append($('#informationDesc').html());
        wxbData.desc(r.id,function(d){
            d.descType=r.type;
            d.myRole=wxb.init.e.role.roleRank;
            var nid=parseInt(r.id);
            d.hasXt=wxb.information.d.xtJson['ids'].indexOf(nid)!=-1?0:1;
            //d.descState=r.state||"";
            JsTpl('[data-box="desc"]').render(d,'iDesc');
        });
    },
    btn:{
        noUse:function(t,id){
            wxbData.noUse(id,function(){
                var $=wxb.init.e.$,_t=$(t),ta=_t.parent('.article-footer');
                ta.empty().append('<a href="javascript:history.back();" class="btn btn-action btn-rounded btn-blue">返回</a>');
            });
        },
        toAdd:function(t,json){
            var $=wxb.init.e.$,_t=$(t),ta=_t.parent('.article-footer');
            wxb.information.d.xtJson['ids'].push(json.id);
            wxb.information.d.xtJson['list'].push(json);
            sessionStorage.setItem('zbyXt',JSON.stringify(wxb.information.d.xtJson));
            ta.empty().append('<a href="javascript:history.back();" class="btn btn-action btn-rounded btn-blue">返回</a>');
        }
    }
};
//--今日快报详情
wxb.todayDesc={
    i:function(r){
        wxb.init.com.isOk(function(){
            wxb.todayDesc.load(r);
        })
    },
    load:function(r){
        if(!r) return history.back();
        wxb.init.com.menu('information');
        wxbData.todayDesc(r.id,function(nr){
             nr.myRole=wxb.init.e.role.roleRank;
             nr.inMyDeal=nr.approvalUserID==wxb.init.e.userID?1:0;
             JsTpl('.mod-main').render(nr,'todayDesc')
        });
    },
    btn:{
        toSubmit:function(type,tid){
            var $=wxb.init.e.$;
            var od={type:type};
            if(type==1){//请示领导
                wxbData.lead(function(d){
                    var al=layer.open({
                        title:'请示领导',
                        content:JsTpl().render(d,'tips-1'),
                        btn:['请示领导','取消'],
                        yes:function(){
                            JsForm('.askForm').submit(function(fr){
                                if(fr.code==1){
                                    var nd=$.extend(true,{},od,fr.result);
                                    wxbData.todayAsk(tid,nd,function(){
                                        setTimeout(function(){history.back()},500)
                                    });
                                    layer.close(al);
                                }else{
                                    layer.msg(fr.msg);
                                }
                            },1);
                        }
                    });
                });
            }else{
                od.advice=$('[name="instructions"]').val();
                wxbData.todayAsk(tid,od,function(){
                    setTimeout(function(){history.back()},500)
                });
            }
        },
        toSeeDesc:function(id){
            wxbData.desc(id,function(rd){
                rd.descType=rd['infoType'];
                layer.open({
                    title:'选题详情',
                    content:'<div style="max-height: 550px;overflow-y:auto">'+JsTpl().render(rd,'iDesc')+'</div>',
                    btn:!0
                });
            })
        },
        toAddXt:function(){
            var xt=sessionStorage.getItem('zbyXt'),nd={};
            if(xt){
                wxb.information.d.xtJson=JSON.parse(xt);
                nd=$.extend(true,{},wxb.information.d.xtJson);
            }
            var hl='<div class="tips-xt-box"><ul class="mesList-wrap" data-list="topicList" data-checkbox="topic">'+JsTpl().render(nd,'list-item-4')+'</ul></div>';
            var ly=layer.open({
                title:'选题列表',
                content:hl,
                btn:['确定','取消'],
                yes:function(){
                    $.each($('.tips-xt-box').find('.checkR:checked'),function(m,n){
                        var _t=$(n),td=_t.data('id');
                        var idx=wxb.information.d.xtJson['ids'].indexOf(td);
                        var nj=wxb.information.d.xtJson['list'][idx];
                        var item='<tr class="table-content" data-id="'+td+'">' +
                                    '<td class="flex2">'+nj.title+'</td>' +
                                    '<td>'+nj.type+'</td>' +
                                    '<td>'+nj.deliveryUnit+'</td>' +
                                    '<td>'+nj.deliveryMan+'</td>' +
                                    '<td class="flex2">'+nj.createTime+'</td>' +
                                    '<td><a href="javascript:wxb.todayDesc.btn.toSeeDesc('+td+');" class="btn btn-small btn-blue btn-rounded">查看详情</a></td>' +
                                '</tr>';
                        $('.tb-wrap tbody').append(item)
                    });
                    layer.close(ly);
                }
            })
        }
    }
};
//--选题列表
wxb.topic={
    i:function(){
        wxb.init.com.isOk(function(){
            wxb.topic.load()
        });
    },
    load:function(){
        var xt=sessionStorage.getItem('zbyXt');
        if(!xt) return history.back();
        wxb.information.d.xtJson=JSON.parse(xt);
        wxb.init.com.menu('information');
        var $=wxb.init.e.$;
        $('.mod-main').empty().append($('#topic').html());
        var nd=$.extend(true,{},wxb.information.d.xtJson);
        JsTpl('[data-list="topicList"]').render(nd,'list-item-4');
    },
    btn:{
        del:function(id){
            var idx=wxb.information.d.xtJson['ids'].indexOf(id);
            wxb.information.d.xtJson['ids'].splice(idx,1);
            wxb.information.d.xtJson['list'].splice(idx,1);
            wxb.init.e.$('.item[data-id="'+id+'"]').remove();
            wxb.information.d.hasCheckNum--;
            sessionStorage.setItem('zbyXt',JSON.stringify(wxb.information.d.xtJson));
        },
        askFor:function(){
            var $=wxb.init.e.$,box=$('[data-list="topicList"]'),ids=[];
            if(box.find('.checkR:checked').length==0) return layer.msg('请先勾选选题!');
            $.each(box.find('.checkR:checked'),function(m,n){
                var _t=$(n),td=_t.data('id');
                ids.push(td)
            });
            wxbData.lead(function(d){
                var al=layer.open({
                    title:'请示领导',
                    content:JsTpl().render(d,'tips-1'),
                    btn:['请示领导','取消'],
                    yes:function(){
                        JsForm('.askForm').submit(function(r){
                            if(r.code==1){
                                r.result['baseIDs']=ids.join(',');
                                wxbData.askLead(r.result,function(){//提交请示
                                    layer.close(al);
                                    $.each(ids,function(m,n){
                                        wxb.topic.btn.del(n);
                                    });
                                    setTimeout(function(){history.back()},800)
                                });
                            }else{
                                layer.msg(r.msg);
                            }
                        },1);
                    }
                });
            });
        }
    }
};
//--新增信息
wxb.add={
    d:{
        type:1,
        isSubmit:false,
        riskTypeList:'',
        eventFirstList:'',
        eventSecList:{},
        regionList:'',
        industryList:''
    },
    i:function(r){
        wxb.add.d.type=r.type||1;
        wxb.add.d.isSubmit=false;
        wxb.init.com.isOk(function(){
            switch (wxb.init.e.role.roleRank){
                case 2:
                case "2":
                case 3:
                case "3":
                case 5:
                case "5":
                case 6:
                case "6":
                    wxb.add.load(r);
                    break;
                default:
                    location.hash='/index';
                    break;
            }
        });
    },
    selectList:function(type){
        var $=wxb.init.e.$;
        var tf=function(b,v,c){
            var li='';
            $.each(v,function(m,n){
                li+=c?'<li fm-value="'+n.id+'" onclick="wxb.add.btn.secSelect('+n.id+')">'+n.name+'</li>':'<li fm-value="'+n.id+'" >'+n.name+'</li>';
            });
            b.empty().append(li);
        };
        switch (type){
            case 1:
                var box1=$('[fm-name="primaryRiskType"]');
                if(wxb.add.d.riskTypeList){
                    tf(box1,wxb.add.d.riskTypeList)
                }else{
                    wxbData.type(2,function(r){
                        wxb.add.d.riskTypeList=r;
                        tf(box1,wxb.add.d.riskTypeList)
                    });
                }
                break;
            case 2:
                var box2=$('[fm-name="primaryEventTypeFirst"]');
                if(wxb.add.d.eventFirstList){
                    tf(box2,wxb.add.d.eventFirstList,1)
                }else{
                    wxbData.type(3,function(r){
                        wxb.add.d.eventFirstList=r;
                        tf(box2,wxb.add.d.eventFirstList,1)
                    },wxb.add.d.eventSecList)
                }
                break;
            case 3:
                var box3=$('[fm-name="regionIDs"]');
                if(wxb.add.d.regionList){
                    tf(box3,wxb.add.d.regionList)
                }else{
                    wxbData.region(function(r){
                        wxb.add.d.regionList=r;
                        tf(box3,wxb.add.d.regionList)
                    });
                }
                break;
            case 4:
                var box4=$('[fm-name="industryIDs"]');
                if(wxb.add.d.industryList){
                    tf(box4,wxb.add.d.industryList)
                }else{
                    wxbData.industry(function(r){
                        wxb.add.d.industryList=r;
                        tf(box4,wxb.add.d.industryList)
                    });
                }
                break;
        }
    },
    ready:function(){
        wxb.add.selectList(1);//风险类型
        wxb.add.selectList(2);//事件类型
        wxb.add.selectList(3);//地域
        wxb.add.selectList(4);//行业

        //初始化当前界面
        $('[data-tab="iat'+wxb.add.d.type+'"]').click();
        //初始化组件
        $.jeDate('.happenTime1',{
            format:'YYYY-MM-DD hh:mm',
            isinitVal:true,
            maxDate: $.nowDate({DD:"0"})
        });
        $.jeDate('.happenTime2',{
            format:'YYYY-MM-DD hh:mm',
            isinitVal:true,
            maxDate: $.nowDate({DD:"0"})
        });
        $.jeDate('.happenTime3',{
            format:'YYYY-MM-DD hh:mm',
            isinitVal:true,
            maxDate: $.nowDate({DD:"0"})
        });
        $.jeDate('.endToday',{
            format:'YYYY-MM-DD hh:mm',
            minDate: $.nowDate({DD:"0"})
        });
        if(wxb.add.d.type==1){
            wxb.add.d.editorContent=wxb.init.textarea('content');
        }
    },
    load:function(lr){
        if(lr.from==3){
            wxb.init.com.menu('placeAdd');
        }else{
            wxb.init.com.menu('information');
        }
        var $=wxb.init.e.$;
        $('.mod-main').empty().append($('#add').html());
        JsTpl('.info-add-con[data-tcon="iat1"]').render(wxb.init.e.userInfo,'add-item-1');
        JsTpl('.info-add-con[data-tcon="iat2"]').render(wxb.init.e.userInfo,'add-item-2');
        JsTpl('.info-add-con[data-tcon="iat3"]').render(wxb.init.e.userInfo,'add-item-3');
        wxb.add.ready();
    },
    set:function(t){
        wxb.add.d.type=t;
        if(wxb.add.d.type==1){
            wxb.add.d.editorContent=wxb.init.textarea('content');
        }
    },
    btn:{
        toSubmit:function(){
            if(wxb.add.d.isSubmit){
                return layer.msg('数据提交中,请稍后在试!');
            }
            var $=wxb.init.e.$,na=[];
            if(wxb.add.d.type==1){
                $('[name="content"]').val(wxb.add.d.editorContent.html());
            }
            JsForm('.info-add-type'+wxb.add.d.type).submit(function(r){
                if(r.code==1){
                    $.each($('.info-add-type'+wxb.add.d.type).find('.tr-item'),function(m,n){
                        var nj={};
                        nj['name']=$(n).find('input[name="name"]').val();
                        nj['unit']=$(n).find('input[name="unit"]').val();
                        nj['leadingOfficial']=$(n).find('input[name="leadingOfficial"]').val();
                        nj['contactPhone']=$(n).find('input[name="contactPhone"]').val();
                        nj['ip']=$(n).find('input[name="ip"]').val();
                        nj['domainName']=$(n).find('input[name="domainName"]').val();
                        nj['url']=$(n).find('input[name="url"]').val();
                        if(nj['name'].replace(/\s/g,'')!=''||nj['unit'].replace(/\s/g,'')!=''||nj['leadingOfficial'].replace(/\s/g,'')!=''||nj['contactPhone'].replace(/\s/g,'')!=''||nj['ip'].replace(/\s/g,'')!=''||nj['domainName'].replace(/\s/g,'')!=''||nj['url'].replace(/\s/g,'')!=''){
                            na.push(nj)
                        }
                    });
                    if(na.length>0){
                        r.result['infrastructure_information']=JSON.stringify(na)
                    }
                    wxbData.add(wxb.add.d.type,r.result)
                }else{
                    layer.msg(r.msg);
                }
            },1)
        },
        onBlur:function(t,type){
            var $=wxb.init.e.$,_v=$(t).text(),tn=$(t).next('input');
            var yz=function(type){
                return (type in JsForm())?!JsForm()[type](_v)?'':_v:_v;
            };
            var nv=yz(type);
            $(t).text(nv);
            tn.val(nv)
        },
        toAddTr:function(t){
            var $=wxb.init.e.$,_t=$(t),tr=_t.parents('tr');
            tr.before(JsTpl().render({},'add-tr-item'));
        },
        toDelTr:function(t){
            var $=wxb.init.e.$,_t=$(t);
            _t.parents('tr').remove();
        },
        secSelect:function(id){
            var li='',box=wxb.init.e.$('[fm-name="primaryEventTypeSecond"]');
            $.each(wxb.add.d.eventSecList[id],function(m,n){
                li+='<li fm-value="'+n.id+'" >'+n.name+'</li>';
            });
            li=li?li:'<li fm-value="-1" >其他</li>';
            box.prev('.form-select-title').find('input').val("");
            box.next('input').val("");
            box.empty().append(li);
        },
        addAttachment:function(){
            wxbData.attachment(function(f){
                var $=wxb.init.e.$,span='';
                $.each(f,function(x,y){
                    span+='<span>'+y.fileName+'</span>';
                });
                $('.fileName').empty().append(span);
                //layer.alert(JSON.stringify(f))
            });
        }
    }
};
//--改变信息
wxb.changeAdd={
    d:{
        type:2
    },
    i:function(r){
        wxb.changeAdd.d.type=r.type;
        wxb.init.com.isOk(function(){
            switch (wxb.init.e.role.roleRank){
                case 1:
                case 2:
                case "1":
                case "2":
                    wxb.changeAdd.load(r);
                    break;
                default:
                    location.hash='/index';
                    break;
            }
        });
    },
    ready:function(){
        wxb.add.selectList(1);//风险类型
        wxb.add.selectList(2);//事件类型
        wxb.add.selectList(3);//地域
        wxb.add.selectList(4);//行业
        //初始化组件
        JsForm('.info-changeAdd-box').render();
        if(wxb.changeAdd.d.type==2){
            $.jeDate('.happenTime2',{
                format:'YYYY-MM-DD hh:mm',
                maxDate: $.nowDate({DD:"0"})
            });
        }else if(wxb.changeAdd.d.type==3){
            $.jeDate('.happenTime3',{
                format:'YYYY-MM-DD hh:mm',
                maxDate: $.nowDate({DD:"0"})
            });
            $.jeDate('.endToday',{
                format:'YYYY-MM-DD hh:mm',
                minDate: $.nowDate({DD:"0"})
            });
        }
    },
    load:function(r){
        wxb.init.com.menu('information');
        var $=wxb.init.e.$;
        JsTpl('.mod-main').render(r,'changeAdd');
        wxbData.desc(r.id,function(d){
            var nd=$.extend(true,{},wxb.init.e.userInfo,d);
            nd.adviceShow=1;
            JsTpl('.info-changeAdd-box').render(nd,'add-item-'+r.type);
            wxb.changeAdd.ready();
        });
    },
    btn:{
        toSubmit:function(){
            if(wxb.add.d.isSubmit){
                return layer.msg('数据提交中,请稍后在试!');
            }
            JsForm('.info-add-type'+wxb.changeAdd.d.type).submit(function(r){
                if(r.code==1){
                    var $=wxb.init.e.$,na=[];
                    $.each($('.info-add-type'+wxb.changeAdd.d.type).find('.tr-item'),function(m,n){
                        var nj={};
                        nj['name']=$(n).find('input[name="name"]').val();
                        nj['unit']=$(n).find('input[name="unit"]').val();
                        nj['leadingOfficial']=$(n).find('input[name="leadingOfficial"]').val();
                        nj['contactPhone']=$(n).find('input[name="contactPhone"]').val();
                        nj['ip']=$(n).find('input[name="ip"]').val();
                        nj['domainName']=$(n).find('input[name="domainName"]').val();
                        nj['url']=$(n).find('input[name="url"]').val();
                        if(nj['name'].replace(/\s/g,'')!=''||nj['unit'].replace(/\s/g,'')!=''||nj['leadingOfficial'].replace(/\s/g,'')!=''||nj['contactPhone'].replace(/\s/g,'')!=''||nj['ip'].replace(/\s/g,'')!=''||nj['domainName'].replace(/\s/g,'')!=''||nj['url'].replace(/\s/g,'')!=''){
                            na.push(nj)
                        }
                    });
                    if(na.length>0){
                        r.result['infrastructure_information']=JSON.stringify(na)
                    }
                    wxbData.lead(function(d){
                        var al=layer.open({
                            title:'请示领导',
                            content:JsTpl().render(d,'tips-1'),
                            btn:['请示领导','取消'],
                            yes:function(){
                                JsForm('.askForm').submit(function(fr){
                                    if(fr.code==1){
                                        var nd=$.extend(true,{},r.result,fr.result);
                                        wxbData.change(nd,wxb.changeAdd.d.type,function(){//提交请示
                                            layer.close(al);
                                            setTimeout(function(){
                                                history.back();
                                            },500);
                                        });
                                    }else{
                                        layer.msg(fr.msg);
                                    }
                                },1);
                            }
                        });
                    });
                }else{
                    layer.msg(r.msg);
                }
            },1);
        },
        toExpertsRead:function(){
            if(wxb.add.d.isSubmit){
                return layer.msg('数据提交中,请稍后在试!');
            }
            JsForm('.info-add-type'+wxb.changeAdd.d.type).submit(function(r){
                if(r.code==1){
                    var $=wxb.init.e.$,na=[];
                    $.each($('.info-add-type'+wxb.changeAdd.d.type).find('.tr-item'),function(m,n){
                        var nj={};
                        nj['name']=$(n).find('input[name="name"]').val();
                        nj['unit']=$(n).find('input[name="unit"]').val();
                        nj['leadingOfficial']=$(n).find('input[name="leadingOfficial"]').val();
                        nj['contactPhone']=$(n).find('input[name="contactPhone"]').val();
                        nj['ip']=$(n).find('input[name="ip"]').val();
                        nj['domainName']=$(n).find('input[name="domainName"]').val();
                        nj['url']=$(n).find('input[name="url"]').val();
                        if(nj['name'].replace(/\s/g,'')!=''||nj['unit'].replace(/\s/g,'')!=''||nj['leadingOfficial'].replace(/\s/g,'')!=''||nj['contactPhone'].replace(/\s/g,'')!=''||nj['ip'].replace(/\s/g,'')!=''||nj['domainName'].replace(/\s/g,'')!=''||nj['url'].replace(/\s/g,'')!=''){
                            na.push(nj)
                        }
                    });
                    if(na.length>0){
                        r.result['infrastructure_information']=JSON.stringify(na)
                    }
                    wxbData.experts(function(d){
                        var al=layer.open({
                            title:'专家研判',
                            content:JsTpl().render(d,'tips-1'),
                            btn:['研判','取消'],
                            yes:function(){
                                JsForm('.askForm').submit(function(fr){
                                    if(fr.code==1){
                                        var nd=$.extend(true,{},r.result,fr.result);
                                        wxbData.change(nd,wxb.changeAdd.d.type,function(){//提交研判
                                            layer.close(al);
                                            setTimeout(function(){
                                                history.back();
                                            },500);
                                        });
                                    }else{
                                        layer.msg(fr.msg);
                                    }
                                },1);
                            }
                        });
                    });
                }else{
                    layer.msg(r.msg);
                }
            },1);
        }
    }
};
//--地方信息新增,专家信息新增,安全厂商信息新增
wxb.placeAdd={
    d:{
        padSx:{}
    },
    i:function(r){
        wxb.init.com.isOk(function(){
            switch (wxb.init.e.role.roleRank){
                case 3:
                case "3":
                case 5:
                case "5":
                case 6:
                case "6":
                    wxb.placeAdd.load(r);
                    break;
                default:
                    location.hash='/index';
                    break;
            }
        });
    },
    reset:function(t){
        wxb.placeAdd.d.padSx={
            userID:wxb.init.e.userID,
            page:1,//分页
            type:t,//类型：1信息,2风险,3事件
            startTime:'',//开始时间
            endTime:'',//结束时间
            title:''//标题
        };
    },
    com:{
        time:function(box,data,fun){
            var start={
                format:'YYYY-MM-DD',
                maxDate:$.nowDate({DD:"0"}),
                okfun:function(v){
                    end.minDate =v.val;
                    wxb.placeAdd.d[data]['startTime']=v.val;
                    wxb.placeAdd.com[fun].call(this);
                    endDates();
                },
                clearfun:function(){
                    wxb.placeAdd.d[data]['startTime']='';
                    wxb.placeAdd.com[fun].call(this);
                }
            };
            var end={
                format:'YYYY-MM-DD',
                maxDate:$.nowDate({DD:"0"}),
                okfun:function(v){
                    start.maxDate=v.val;
                    wxb.placeAdd.d[data]['endTime']=v.val;
                    wxb.placeAdd.com[fun].call(this);
                },
                clearfun:function(){
                    wxb.placeAdd.d[data]['endTime']='';
                    wxb.placeAdd.com[fun].call(this);
                }
            };
            function endDates() {
                end.trigger = false;
                $.jeDate('#'+box+'_end',end);
            }
            $.jeDate('#'+box+'_start',start);
            $.jeDate('#'+box+'_end',end);
        },
        toList:function(){
            var d=wxb.placeAdd.d.padSx;
            wxbData.placeList(d,function(r){
                dclData(r,r['current']);
                //分页初始化
                JsPage('.ib-page[data-page="padPage"]').render(r['total'],r['current'],function(ck){
                    d.page=ck;
                    wxbData.placeList(d,function(cr){
                        dclData(cr,ck);
                    })
                });
            });
            var dclData=function(dr,page){//数据填充
                JsTpl('[data-list="padList"]').render(dr,'place-item-'+d.type,page);
            }
        }
    },
    load:function(r){
        wxb.init.com.menu('placeAdd');
        var tabNav=r['tabNav']||1;
        JsTpl('.mod-main').render({tabNav:tabNav},'placeAdd');
        wxb.placeAdd.com.time('pad','padSx','toList');
        $('.btn-info-type').eq(0).click();
    },
    btn:{
        keydown:function(e,t){//标题搜索
            var $=wxb.init.e.$,_t=$(t);
            if(e.keyCode==13){
                wxb.placeAdd.d.padSx['title']=_t.val();
                wxb.placeAdd.com.toList();
            }
        },
        tabType:function(t,tt){
            var $=wxb.init.e.$,_t=$(t);
            if(!_t.hasClass('active')){
                _t.addClass('active').siblings().removeClass('active');
                var nd={type:tt};
                JsTpl('.form-type-box').render(nd,'placeType');
                wxb.placeAdd.reset(tt);
                wxb.placeAdd.com.toList();
            }
        }
    }
};

//每日零报告
wxb.report={
    d:{
        reportSx:{}
    },
    i:function(r){
        wxb.init.com.isOk(function(){
            switch (wxb.init.e.role.roleRank){
                case 1://领导
                case "1":
                    wxb.report.load(r);
                    break;
                case 2://值班员
                case "2":
                    wxb.report.load2(r);
                    break;
                case 3://地方
                case "3":
                case 4://运营单位
                case "4":
                    wxb.report.load3(r);
                    break;
                default://其他角色进来时
                    location.hash='/index';
                    break;
            }
        });
    },
    reset:function(t){
        wxb.report.d.reportSx={
            flag:t,
            page:1,
            startTime:'',
            endTime:''
        };
    },
    com:{
        time:function(box,data,fun){
            var start={
                maxDate:$.nowDate({DD:"0"}),
                okfun:function(v){
                    end.minDate =v.val;
                    wxb.report.d[data]['startTime']=v.val;
                    wxb.report.com[fun].call(this);
                    endDates();
                },
                clearfun:function(){
                    wxb.report.d[data]['startTime']='';
                    wxb.report.com[fun].call(this);
                }
            };
            var end={
                maxDate:$.nowDate({DD:"0"}),
                okfun:function(v){
                    start.maxDate=v.val;
                    wxb.report.d[data]['endTime']=v.val;
                    wxb.report.com[fun].call(this);
                },
                clearfun:function(){
                    wxb.report.d[data]['endTime']='';
                    wxb.report.com[fun].call(this);
                }
            };
            function endDates() {
                end.trigger = false;
                $.jeDate('#'+box+'_end',end);
            }
            $.jeDate('#'+box+'_start',start);
            $.jeDate('#'+box+'_end',end);
        },
        reportList:function(){
            var d=wxb.report.d.reportSx;
            wxbData.reportList(d,function(r){
                reportData(r,r['current']);
                JsPage('.ib-page[data-page="zeroReport"]').render(r['total'],r['current'],function(ck){
                    d.page=ck;
                    wxbData.reportList(d,function(cr){
                        reportData(cr,ck);
                    })
                });
            });
            var reportData=function(dr,page){
                JsTpl('[data-list="zeroReport"]').render(dr,'zeroReport-item-'+d.flag,page);
            }
        },
        reportList3:function(){//地方
            var d=wxb.report.d.reportSx;
            wxbData.reportList(d,function(r){
                reportData(r,r['current']);
                JsPage('.ib-page[data-page="zeroReport"]').render(r['total'],r['current'],function(ck){
                    d.page=ck;
                    wxbData.reportList(d,function(cr){
                        reportData(cr,ck);
                    })
                });
            });
            var reportData=function(dr,page){
                JsTpl('[data-list="zeroReport"]').render(dr,'myReport-item-'+d.flag,page);
            }
        }
    },
    load:function(r){
        wxb.init.com.menu('report');
        var $=wxb.init.e.$;
        var tabNav=r['tabNav']||0;
        JsTpl('.mod-main').render({tabNav:tabNav},'report2');
        $('.article-bd').empty().append($('#report-item-1').html());
        wxb.report.reset(tabNav);
        wxb.report.com.time('zeroReport','reportSx','reportList');
        wxb.report.com.reportList();
    },
    load2:function(r){
        wxb.init.com.menu('report');
        var $=wxb.init.e.$;
        var tabNav=r['tabNav']||0;
        JsTpl('.mod-main').render({tabNav:tabNav},'report2');
        $('.article-bd').empty().append($('#report-item-'+tabNav).html());
        wxb.report.reset(tabNav);
        wxb.report.com.time('zeroReport','reportSx','reportList');
        wxb.report.com.reportList();
    },
    load3:function(r){
        wxb.init.com.menu('report');
        var $=wxb.init.e.$;
        var tabNav=r['tabNav']||0;
        JsTpl('.mod-main').render({tabNav:tabNav},'report2');
        $('.article-bd').empty().append($('#report-item-3').html());
        wxb.report.reset(tabNav);
        wxb.report.com.time('zeroReport','reportSx','reportList');
        wxb.report.com.reportList3();
    },
    btn:{
        toDesc:function(id,type){
            if(type==1){
                location.hash='/reportDesc?id='+id
            }else{
                location.hash='/reportAdd?id='+id
            }
        },
        toDesc3:function(id){
            location.hash='/reportDesc?fid='+id
        }
    }
};
//--新增每日零报告
wxb.reportAdd={
    d:{
        orgMen:'',
        hasCkMan:[]//已选人员
    },
    i:function(r){
        wxb.init.com.isOk(function(){
            wxb.reportAdd.load(r);
        })
    },
    com:{
        ready:function(nd){
            wxb.reportAdd.d.hasCkMan=nd?nd['orgList']:[];
            nd=nd||wxb.init.e.userInfo;
            JsTpl('.article-bd').render(nd,'reportAdd-item');
            //初始化时间
            var start={
                format:'YYYY-MM-DD',
                minDate:$.nowDate({DD:"0"}),
                okfun:function(v){
                    end.minDate =v.val;
                    endDates();
                }
            };
            var end={
                format:'YYYY-MM-DD',
                okfun:function(v){
                    start.maxDate=v.val;
                }
            };
            function endDates() {
                end.trigger = false;
                $.jeDate('[name="cycleEndTime"]',end);
            }
            $.jeDate('[name="cycleStartTime"]',start);
            $.jeDate('[name="cycleEndTime"]',end);

            $.jeDate('[name="dailyReleaseTime"]',{
                format:'hh:mm'
            });
            $.jeDate('[name="dailyEndedTime"]',{
                format:'hh:mm'
            });
        },
        orgMenShow:function(){
            var $=wxb.init.e.$;
            var ly=layer.open({
                title:"选择组织",
                content:$('#orgTips').html(),
                btn:['确定','取消'],
                yes:function(){
                    var span='',hasID=[];
                    wxb.reportAdd.d.hasCkMan=wxb.orgFun.d.hasCk;
                    $('.form-unit-item').remove();
                    $.each(wxb.reportAdd.d.hasCkMan,function(m,n){
                        var id=n['orgID'];
                        hasID.push(id);
                        span+='<div class="form-unit-item"><a href="javascript:;" data-id="'+id+'" class="form-unit-close">x</a><img src="../images/abs-org.png"><p>'+n['orgName']+'</p></div>';
                        layer.close(ly);
                    });
                    $('.form-unit-box').prepend(span);
                    $('[name="selections"]').val(JSON.stringify(hasID));
                }
            });
            wxb.orgFun.init($('.modOrg'),wxb.reportAdd.d.hasCkMan);
        },
        del:function(id){
            var d=wxb.reportAdd.d.hasCkMan,nj=[],nid=[];
            wxb.init.e.$.each(d,function(m,n){
                if(n.orgID!=id){
                    nid.push(n['orgID']);
                    nj.push(n)
                }
            });
            wxb.reportAdd.d.hasCkMan=nj;
            wxb.init.e.$('[name="selections"]').val(JSON.stringify(nid));
        }
    },
    load:function(r){
        wxb.init.com.menu('report');
        var $=wxb.init.e.$;
        $('.mod-main').empty().append($('#reportAdd').html());
        if(r.id){
            wxbData.reportDesc(1,r.id,function(r){
                if(r['isRelease']==1){
                    history.back();
                }else{
                    wxb.reportAdd.com.ready(r);
                }
            })
        }else{
            wxb.reportAdd.com.ready();
        }
    },
    btn:{
        toSubmit:function(type){
            if(wxb.add.d.isSubmit){
                return layer.msg('数据提交中,请稍后在试!');
            }
            JsForm('.zeroReportForm').submit(function(r){
                if(r.code==1){
                    wxbData.reportAdd(type,r.result)
                }else{
                    layer.msg(r.msg);
                }
            },1)
        },
        toAddPeople:function(){
            wxb.reportAdd.com.orgMenShow();
        },
        toCheck:function(){
            var $=wxb.init.e.$,body=$('body');
            body.on('click','.form-unit-close',function(){
                var _t=wxb.init.e.$(this),id=_t.data('id');
                wxb.reportAdd.com.del(id);
                _t.parent('.form-unit-item').remove();
            });
        }
    }
};
//--每日零报告详情
wxb.reportDesc={
    d:{
        feedbackSx:{}
    },
    i:function(r){
        wxb.init.com.isOk(function(){
            wxb.reportDesc.load(r);
        })
    },
    reset:function(id,s){
        wxb.reportDesc.d.feedbackSx={
            page: 1,
            reportID: id,
            isSubmit: s //(0--未反馈;1--已反馈)
        };
    },
    com:{
        toTable:function(){//拉取列表
            var d=wxb.reportDesc.d.feedbackSx;
            wxbData.reportTable(d,function(r){
                fdData(r,r['current']);
                JsPage('.ib-page[data-page="feedbackPage"]').render(r['total'],r['current'],function(ck){
                    d.page=ck;
                    wxbData.reportTable(d,function(cr){
                        fdData(cr,ck);
                    })
                });
            });
            var fdData=function(dr,page){
                JsTpl('.feedbackList').render(dr,'feedbackList',page);
            }
        }
    },
    load:function(r){
        wxb.init.com.menu('report');
        var $=wxb.init.e.$;
        $('.mod-main').empty().append($('#reportDesc').html());
        if(r.fid){
            wxbData.reportDesc(2,r.fid,function(r){
                var nd=$.extend(true,{},r,wxb.init.e.userInfo);
                nd.writerTime=(new Date()).Format('yyyy-MM-dd hh:mm:ss');
                JsTpl('.article-bd').render(nd,'drDesc');
            });
        }else if(r.id){
            wxbData.reportDesc(1,r.id,function(r){
                JsTpl('.article-bd').render(r,'rDesc');
                wxb.reportDesc.reset(r.id,0);
                wxb.reportDesc.com.toTable();
            })
        }else{
            history.back();
        }
    },
    btn:{
        toSubmit:function(){
            JsForm('.form-details').submit(function(r){
                if(r.code==1){
                    wxbData.reportFeedback(r.result,function(){
                        history.back();
                    });
                }else{
                    layer.msg(r.msg);
                }
            },1)
        },
        change:function(t){
            var _t=wxb.init.e.$(t);
            wxb.reportDesc.d.feedbackSx['isSubmit']=_t.val();
            wxb.reportDesc.com.toTable();
        }
    }
};

//事件管理
wxb.eventManage={
    d:{
        eventSx:{}
    },
    i:function(r){
        wxb.init.com.isOk(function(){
            switch (wxb.init.e.role.roleRank){
                case 1:
                case 2:
                case "1":
                case "2":
                    wxb.eventManage.load(r);
                    break;
                default:
                    location.hash='/index';
                    break;
            }
        })
    },
    ready:function(tabNav){
        var nj={};
        if(wxb.add.d.eventFirstList){
            nj.eventList=wxb.add.d.eventFirstList;
            JsTpl('.article-bd').render(nj,'event-Sx-'+tabNav);
            wxb.eventManage.com.toList();
        }else{
            wxbData.type(3,function(r){
                wxb.add.d.eventFirstList=r;
                nj.eventList=wxb.add.d.eventFirstList;
                JsTpl('.article-bd').render(nj,'event-Sx-'+tabNav);
                wxb.eventManage.com.toList();
            },wxb.add.d.eventSecList)
        }
    },
    reset:function(s){
        wxb.eventManage.d['eventSx']={
            page:1,//分页
            status:s,//1在办,2办结
            startTime:'',//开始时间
            endTime:'',//结束时间
            title:'',//标题
            timeType:'1',
            eventLevel:'',
            eventType:''
        };
    },
    com:{
        time:function(box,data,fun){
            var start={
                format:'YYYY-MM-DD',
                maxDate:$.nowDate({DD:"0"}),
                okfun:function(v){
                    end.minDate =v.val;
                    wxb.eventManage.d[data]['startTime']=v.val;
                    wxb.eventManage.com[fun].call(this);
                    endDates();
                },
                clearfun:function(){
                    wxb.eventManage.d[data]['startTime']='';
                    wxb.eventManage.com[fun].call(this);
                }
            };
            var end={
                format:'YYYY-MM-DD',
                maxDate:$.nowDate({DD:"0"}),
                okfun:function(v){
                    start.maxDate=v.val;
                    wxb.eventManage.d[data]['endTime']=v.val;
                    wxb.eventManage.com[fun].call(this);
                },
                clearfun:function(){
                    wxb.eventManage.d[data]['endTime']='';
                    wxb.eventManage.com[fun].call(this);
                }
            };
            function endDates() {
                end.trigger = false;
                $.jeDate('#'+box+'_end',end);
            }
            $.jeDate('#'+box+'_start',start);
            $.jeDate('#'+box+'_end',end);
        },
        toList:function(){
            var d=wxb.eventManage.d.eventSx;
            wxbData.getEventRisk(3,d,function(r){
                listData(r,r['current']);
                JsPage('.ib-page[data-page="managePage"]').render(r['total'],r['current'],function(ck){
                    d.page=ck;
                    wxbData.getEventRisk(3,d,function(cr){
                        listData(cr,ck);
                    })
                });
            });
            var listData=function(dr,page){
                JsTpl('[data-list="manageList"]').render(dr,'event-item-'+d.status,page);
            }
        }
    },
    load:function(r){
        wxb.init.com.menu('eventManage');
        var tabNav=r['tabNav']||0;
        JsTpl('.mod-main').render({path:'eventManage',tabNav:tabNav},'managePage');
        wxb.eventManage.reset(tabNav);
        wxb.eventManage.ready(tabNav);
        wxb.eventManage.com.time('manage','eventSx','toList');
    },
    btn:{
        keydown:function(e,t){//标题搜索
            var $=wxb.init.e.$,_t=$(t);
            if(e.keyCode==13){
                wxb.eventManage.d.eventSx['title']=_t.val();
                wxb.eventManage.com.toList();
            }
        },
        change:function(t){
            wxb.eventManage.d.eventSx['timeType']=wxb.init.e.$(t).val();
            wxb.eventManage.com.toList();
        },
        form:function(fc){
            JsForm('[data-form="'+fc+'"]').submit(function(r){
                var n;
                if(fc in r.result){
                    if((fc+'All') in r.result){
                        n=''
                    }else{
                        n=r.result[fc]
                    }
                }else{
                    n='';
                }
                wxb.eventManage.d['eventSx'][fc]=n;
                wxb.eventManage.com.toList();
            },1)
        }
    }
};

//预警管理
wxb.riskManage={
    d:{
        riskSx:{}
    },
    i:function(r){
        wxb.init.com.isOk(function(){
            switch (wxb.init.e.role.roleRank){
                case 1:
                case 2:
                case "1":
                case "2":
                    wxb.riskManage.load(r);
                    break;
                default:
                    location.hash='/index';
                    break;
            }
        })
    },
    ready:function(tabNav){
        var nj={};
        JsTpl('.article-bd').render(nj,'risk-Sx-'+tabNav);
        wxb.riskManage.com.toList();
    },
    reset:function(s){
        wxb.riskManage.d['riskSx']={
            page:1,//分页
            status:s,//1在办,2办结
            startTime:'',//开始时间
            endTime:'',//结束时间
            title:'',//标题
            timeType:'1',
            riskLevel:'',
            warningLevel:''
        };
    },
    com:{
        time:function(box,data,fun){
            var start={
                format:'YYYY-MM-DD',
                maxDate:$.nowDate({DD:"0"}),
                okfun:function(v){
                    end.minDate =v.val;
                    wxb.riskManage.d[data]['startTime']=v.val;
                    wxb.riskManage.com[fun].call(this);
                    endDates();
                },
                clearfun:function(){
                    wxb.riskManage.d[data]['startTime']='';
                    wxb.riskManage.com[fun].call(this);
                }
            };
            var end={
                format:'YYYY-MM-DD',
                maxDate:$.nowDate({DD:"0"}),
                okfun:function(v){
                    start.maxDate=v.val;
                    wxb.riskManage.d[data]['endTime']=v.val;
                    wxb.riskManage.com[fun].call(this);
                },
                clearfun:function(){
                    wxb.riskManage.d[data]['endTime']='';
                    wxb.riskManage.com[fun].call(this);
                }
            };
            function endDates() {
                end.trigger = false;
                $.jeDate('#'+box+'_end',end);
            }
            $.jeDate('#'+box+'_start',start);
            $.jeDate('#'+box+'_end',end);
        },
        toList:function(){
            var d=wxb.riskManage.d.riskSx;
            wxbData.getEventRisk(2,d,function(r){
                listData(r,r['current']);
                JsPage('.ib-page[data-page="managePage"]').render(r['total'],r['current'],function(ck){
                    d.page=ck;
                    wxbData.getEventRisk(2,d,function(cr){
                        listData(cr,ck);
                    })
                });
            });
            var listData=function(dr,page){
                JsTpl('[data-list="manageList"]').render(dr,'risk-item-'+d.status,page);
            }
        }
    },
    load:function(r){
        wxb.init.com.menu('riskManage');
        var tabNav=r['tabNav']||0;
        JsTpl('.mod-main').render({path:'riskManage',tabNav:tabNav},'managePage');
        wxb.riskManage.reset(tabNav);
        wxb.riskManage.ready(tabNav);
        wxb.riskManage.com.time('manage','riskSx','toList');
    },
    btn:{
        keydown:function(e,t){//标题搜索
            var $=wxb.init.e.$,_t=$(t);
            if(e.keyCode==13){
                wxb.riskManage.d.riskSx['title']=_t.val();
                wxb.riskManage.com.toList();
            }
        },
        change:function(t){
            wxb.riskManage.d.riskSx['timeType']=wxb.init.e.$(t).val();
            wxb.riskManage.com.toList();
        },
        form:function(fc){
            JsForm('[data-form="'+fc+'"]').submit(function(r){
                var n;
                if(fc in r.result){
                    if((fc+'All') in r.result){
                        n=''
                    }else{
                        n=r.result[fc]
                    }
                }else{
                    n='';
                }
                wxb.riskManage.d['riskSx'][fc]=n;
                wxb.riskManage.com.toList();
            },1)
        }
    }
};

//事件/预警详情
wxb.eventRiskDesc={
    d:{
        descJson:{}
    },
    i:function(r){
        wxb.init.com.isOk(function(){
            switch (wxb.init.e.role.roleRank){
                case 1:
                case 2:
                case "1":
                case "2":
                    wxb.eventRiskDesc.load(r);
                    break;
                default:
                    location.hash='/index';
                    break;
            }
        })
    },
    com:function(d){
        d.myRole=wxb.init.e.role.roleRank;
        d.isMyDeal=d['approvalUserID']==wxb.init.e.userID;
        JsTpl('.article-bd').render(d,'erDesc');
    },
    feedList:function(ds,type,id){
        var d={page:1,downsSet:ds,baseID:id};
        wxbData.summary(type,d,function(r){
            fList(r,r['current']);
            JsPage('[data-page="feedback"]').render(r['total'],r['current'],function(ck){
                d.page=ck;
                wxbData.summary(type,d,function(cr){
                    fList(cr,ck);
                })
            });
        });
        var fList=function(dr,page){
            var item=type==2?'feedRiskZby':'feedEventZby';
            if(type==2){
                var fb=wxb.init.e.$('.feedbackBox');
                fb.find('.fr-item').remove();
                fb.prepend(JsTpl().render(dr,'feedRiskZby',page,'',function(ai){
                    ai['isXY']=1;
                    ai['isType']=type;
                    wxb.eventRiskDesc.d.descJson[ai['id']]=ai;
                }))
            }else{
                JsTpl('.feedbackBox').render(dr,'feedEventZby',page,'',function(ai){
                    ai['isXY']=1;
                    ai['isType']=type;
                    wxb.eventRiskDesc.d.descJson[ai['id']]=ai;
                });
            }
        }
    },
    safeList:function(ms,type,id){
        var d={page:1,downsSet:ms,baseID:id};
        wxbData.summary(type,d,function(r){
            fList(r,r['current']);
            JsPage('[data-page="safeBack"]').render(r['total'],r['current'],function(ck){
                d.page=ck;
                wxbData.summary(type,d,function(cr){
                    fList(cr,ck);
                })
            });
        });
        var fList=function(dr,page){
            var item=type==2?'feedEventZby':'feedEventZby';
            JsTpl('.safeBackBox').render(dr,item,page,'',function(ai){
                wxb.eventRiskDesc.d.descJson[ai['id']]=ai;
            });
        }
    },
    load:function(r){
        var $=wxb.init.e.$;
        wxb.eventRiskDesc.d.descJson={};
        if(r.id){
            $('.mod-main').empty().append($('#eventRiskDesc').html());
            wxbData.eventRiskDesc(r.id,function(dr){
                dr.infoType=r.type;
                if(dr['downsSet']){
                    dr['isIssued']=1;
                     wxb.eventRiskDesc.feedList(dr['downsSet'],dr['infoType'],dr['baseID']);
                    dr['infoType']==2&&wxbData.riskTotal({baseID:dr['baseID'],downsSet:dr['downsSet']},function(tr){
                        tr=tr||{};
                        JsTpl('.fr-total').render(tr,'fr-total')
                    });
                    if(dr['manufacturers']){
                        dr['isMfs']=1;
                        wxb.eventRiskDesc.safeList(dr['manufacturers'],dr['infoType'],dr['baseID'])
                    }
                }else{dr['isIssued']=0}
                switch(r.type){
                    case '2'://预警
                    case 2://预警
                        wxb.init.com.menu('riskManage');
                        wxb.eventRiskDesc.com(dr);
                        break;
                    case '3':
                    case 3://事件
                        wxb.init.com.menu('eventManage');
                        wxb.eventRiskDesc.com(dr);
                        break;
                    default:
                        layer.msg('类型不对,即将返回上一页');
                        setTimeout(function(){history.back()},800);
                        break;
                }
            },r.type);
        }else{
            history.back();
        }
    },
    btn:{
        toDesc:function(id,type){
            location.hash='/eventRiskDesc?id='+id+'&type='+type
        },
        update:function(type,id,state){
            var od={baseID:id,type:state};
            switch (state){
                case 1://转批,请示领导
                    wxbData.lead(function(d){
                        var al=layer.open({
                            title:'请示领导',
                            content:JsTpl().render(d,'tips-1'),
                            btn:['请示领导','取消'],
                            yes:function(){
                                JsForm('.askForm').submit(function(fr){
                                    if(fr.code==1){
                                        var nd=$.extend(true,{},od,fr.result);
                                        wxbData.updateEventRisk(type,nd,function(){
                                            setTimeout(function(){location.reload()},300)
                                        });
                                        layer.close(al);
                                    }else{
                                        layer.msg(fr.msg);
                                    }
                                },1);
                            }
                        });
                    });
                    break;
                case 2://同意
                case 3://退回
                    od.advice=$('.advice').val()||(state==2?'同意':'退回');
                    wxbData.updateEventRisk(type,od,function(){
                        setTimeout(function(){location.reload()},300)
                    });
                    break;
                case 4://归档
                    var ly=layer.open({
                        title:'归档',
                        content:$('#archiveTips').html(),
                        yes:function(){
                            JsForm('.archive-form').submit(function(r){
                                if(r.code==1){
                                    od.advice=r.result['advice'];
                                    wxbData.updateEventRisk(type,od,function(){
                                        layer.close(ly);
                                        setTimeout(function(){location.reload()},300)
                                    });
                                }else{
                                    layer.msg(r.msg)
                                }
                            },1)
                        }
                    });
                    break;
                case 5://研判
                    wxbData.experts(function(d){
                        var al=layer.open({
                            title:'专家研判',
                            content:JsTpl().render(d,'tips-1'),
                            btn:['研判','取消'],
                            yes:function(){
                                JsForm('.askForm').submit(function(fr){
                                    if(fr.code==1){
                                        var nd=$.extend(true,{},od,fr.result);
                                        nd.type=1;//研判还是1
                                        wxbData.updateEventRisk(type,nd,function(){
                                            setTimeout(function(){location.reload()},300)
                                        });
                                        layer.close(al);
                                    }else{
                                        layer.msg(fr.msg);
                                    }
                                },1);
                            }
                        });
                    });
                    break;
            }
        },
        issued:function(type,id){
            var $=wxb.init.e.$,nj={};
            var ly=layer.open({
                title:"选择下发单位",
                content:$('#issuedTips').html(),
                btn:['确定','取消'],
                skin:'issuedTips',
                yes:function(){
                    if(wxb.orgFun.d.hasCk.length>0){
                        var _v1=$('textarea[name="replyClaim"]').val();
                        if(_v1.replace(/\s/g,'')=='') return layer.msg('请填写应对要求');
                        nj.baseID=id;
                        nj.downsSet=JSON.stringify(wxb.orgFun.d.hasCk);
                        nj.replyClaim=_v1;
                        if(wxb.orgFun.d.hasCk2.length>0){
                            var _v2=$('textarea[name="handleClaim"]').val();
                            if(_v2.replace(/\s/g,'')=='') return layer.msg('请填写跟踪要求');
                            nj.handleClaim=_v2;
                            nj.manufacturers=JSON.stringify(wxb.orgFun.d.hasCk2);
                        }
                        layer.close(ly);
                        wxbData.release(nj,type,function(){
                            layer.msg('下发成功');
                            setTimeout(function(){
                                location.reload()
                            },300)
                        });
                    }else{
                        layer.msg('没有选取任何下发地方网信办')
                    }
                }
            });
            wxb.orgFun.offices($('.modIssued'));
        },
        flowList:function(fId){
            var type=$('.article-scroll-box').data('type');
            wxbData.flowList(fId,type,function(r){
                layer.open({
                    title:'流转记录',
                    content:JsTpl().render(r,'flowList'),
                    btn:!1,
                    skin:'flowTips'
                })
            })
        },
        deal:function(id){
            var $=wxb.init.e.$;
            var type=$('.article-scroll-box').data('type');
            var ly=layer.open({
                title:"审核",
                content:'<div class="dealTips"><label>审核意见</label><div><textarea name="content"></textarea></div></div>',
                btn:['确定','继续跟踪'],
                yes:function(){
                    var _v=$('textarea[name="content"]').val(),nd={fId:id,exStatus:1,infoType:type};
                    if(_v.replace(/\s/g,'')!=''){
                        nd.content=_v;
                        layer.close(ly);
                        wxbData.operation(nd);
                    }else{
                        layer.msg('请填写审核意见')
                    }
                },
                btn2:function(){
                    var _v=$('textarea[name="content"]').val(),nd={fId:id,exStatus:2,infoType:type};
                    if(_v.replace(/\s/g,'')!=''){
                        nd.content=_v;
                        layer.close(ly);
                        wxbData.operation(nd);
                    }else{
                        layer.msg('请填写审核意见');
                        return false;
                    }

                }
            })
        },
        termination:function(id){
            layer.open({
                title:'警告',
                content:'<div style="text-align:center"><p class="tips-warn"><i class="fui-font fui-font-warn"></i></p>确认要终止反馈吗?</div>',
                btn:['确定','取消'],
                yes:function(){
                    var type=$('.article-scroll-box').data('type');
                    var nd={fId:id,infoType:type,exStatus:3,content:'值班员终止反馈'};
                    wxbData.operation(nd);
                }
            });
        },
        batch:function(exStatus,id,ds){
            var type=$('.article-scroll-box').data('type');
            var nd={baseID:id,orgIDs:ds,exStatus:exStatus,infoType:type};
            nd.content=exStatus==1?'确认':exStatus==2?'继续跟踪':'终止反馈';
            layer.open({
               title:'警告',
                content:'<div style="text-align: center"><p class="tips-warn"><i class="fui-font fui-font-warn"></i></p>确定批量'+nd.content+'</div>',
                btn:['确定','取消'],
                yes:function(){
                    wxbData.batch(nd)
                }
            });
        },
        lookDesc:function(id){
            var d=wxb.eventRiskDesc.d.descJson[id];
            layer.open({
                title:'应对情况',
                content:JsTpl().render(d,'lookDesc'),
                btn:!1
            });
        },
        lookResult:function(fId){
            var type=$('.article-scroll-box').data('type');
            wxbData.flowList(fId,type,function(r){
                layer.open({
                    title:'结果',
                    content:JsTpl().render(r,'flowList'),
                    btn:!1,
                    skin:'flowTips'
                })
            },1)
        }
    }
};

//我的任务
wxb.task={
    d:{
        taskType:0,//0:待处理,1:已办,2:办结
        riskPage:1,
        eventPage:1
    },
    i:function(r){
        wxb.init.com.isOk(function(){
            switch (wxb.init.e.role.roleRank){
                case 3://地方
                case '3':
                case 4://运营
                case '4':
                case 5://安全厂商
                case '5':
                case 6://专家
                case '6':
                    wxb.task.load(r);
                    break;
                default:
                    location.hash='/index';
                    break;
            }
        })
    },
    com:{
        cf:function(box,d){
            if(wxb.init.e.role.roleRank==6){//专家
                wxbData.taskList2(d,function(r){
                    r.infoType=d.type;
                    var $num=d.type==2?wxb.init.e.$('[data-num="risk"]'):wxb.init.e.$('[data-num="event"]');
                    $num.text(r['total']);
                    tp(box,r,r['current'],1);
                    JsPage('[data-page="'+box+'"]').render(r['total'],r['current'],function(ck){
                        d.page=ck;
                        wxbData.taskList2(d,function(cr){
                            cr.infoType=d.type;
                            tp(box,cr,ck,1);
                        })
                    });
                });
            }else{
                wxbData.taskList(d,function(r){
                    r.infoType=d.type;
                    var $num=d.type==2?wxb.init.e.$('[data-num="risk"]'):wxb.init.e.$('[data-num="event"]');
                    $num.text(r['total']);
                    tp(box,r,r['current']);
                    JsPage('[data-page="'+box+'"]').render(r['total'],r['current'],function(ck){
                        d.page=ck;
                        wxbData.taskList(d,function(cr){
                            cr.infoType=d.type;
                            tp(box,cr,ck);
                        })
                    });
                });
            }
            var tp=function(box,dr,page,exp){
                var item=exp?'taskItem2':'taskItem';
                JsTpl('.task-'+box+' .safeDy-list').render(dr,item,page);
            }
        },
        RiskList:function(){
            var d={status:wxb.task.d.taskType,page:wxb.task.d.riskPage,type:2};
            var t=this;
            t.cf('risk',d)
        },
        EventList:function(){
            var d={status:wxb.task.d.taskType,page:wxb.task.d.riskPage,type:3};
            var t=this;
            t.cf('event',d)
        }
    },
    load:function(r){
        wxb.init.com.menu('task');
        var tabNav=r['tabNav']||0;
        wxb.task.d.taskType=tabNav;
        wxb.task.d.riskPage=1;
        wxb.task.d.eventPage=1;
        JsTpl('.mod-main').render({tabNav:tabNav},'task');
        wxb.task.com.RiskList();
        wxb.task.com.EventList();
    },
    btn:{
        toTaskDesc:function(id,type){
            location.hash='/taskDesc?id='+id+'&type='+type;
        },
        toTaskDesc2:function(id,type){
            location.hash='/taskDesc?id='+id+'&type='+type+'&read=1';
        }
    }
};
//任务详情
wxb.taskDesc={
    i:function(r){
        wxb.init.com.isOk(function(){
            switch (wxb.init.e.role.roleRank){
                case 3://地方
                case '3':
                case 4://运营
                case '4':
                case 5://安全厂商
                case '5':
                case 6://专家
                case '6':
                    if(r.read==1){//研判的详情
                        wxb.taskDesc.load2(r);
                    }else{
                        wxb.taskDesc.load(r);
                    }
                    break;
                default:
                    location.hash='/index';
                    break;
            }
        });
    },
    com:function(d){
        d.myRole=wxb.init.e.role.roleRank;
        d.isMyDeal=d['approvalUserID']==wxb.init.e.userID;
        JsTpl('.article-bd').render(d,'erDesc');
    },
    feedList:function(ds,type,id){//反馈列表
        var d={page:1,downsSet:ds,baseID:id};
        wxbData.summary(type,d,function(r){
            fList(r,r['current']);
            JsPage('[data-page="feedback"]').render(r['total'],r['current'],function(ck){
                d.page=ck;
                wxbData.summary(type,d,function(cr){
                    fList(cr,ck);
                })
            });
        });
        var fList=function(dr,page){
            if(type==2){
                var fb=wxb.init.e.$('.feedbackBox');
                fb.find('.fr-item').remove();
                fb.prepend(JsTpl().render(dr,'feedRiskItem',page))
            }else{
                JsTpl('.feedbackBox').render(dr,'feedEventItem',page);
            }
        }
    },
    load:function(r){
        wxb.init.com.menu('task');
        if(r.id){
            wxbData.taskDesc(r.id,function(dr){
                dr.infoType=r.type;
                dr['readonly']=dr['status']==0?'':'readonly';
                dr['myRole']=wxb.init.e.role.roleRank;
                if(dr['downsSet']){
                    dr['isIssued']=true;
                    wxb.taskDesc.feedList(dr['downsSet'],r.type,dr['baseID']);
                    r.type==2&&wxbData.riskTotal({baseID:dr['baseID'],downsSet:dr['downsSet']},function(tr){
                        tr=tr||{};
                        JsTpl('.fr-total').render(tr,'fr-total')
                    });
                }
                JsTpl('.mod-main').render(dr,'taskDesc');
            },r.type);
        }else{
            history.back();
        }
    },
    load2:function(r){
        wxb.init.com.menu('task');
        var $=wxb.init.e.$;
        if(r.id){
            $('.mod-main').empty().append($('#eventRiskDesc').html());
            wxbData.eventRiskDesc(r.id,function(dr){
                dr.infoType=r.type;
                wxb.taskDesc.com(dr);
            },r.type);
        }else{
            history.back();
        }
    },
    btn:{
        toSubmit:function(s,type){
            JsForm('.FeedForm').submit(function(r){
                if(r.code==1){
                    var nd=r.result;
                    nd.status=s;
                    wxbData.feedbackSubmit(nd,type,function(){
                        layer.msg('操作成功');
                        setTimeout(function(){
                            history.back();
                        },300);
                    });
                }else{
                    layer.msg(r.msg)
                }
            },1);
        },
        toIssued:function(type,id){
            var $=wxb.init.e.$;
            var ly=layer.open({
                title:"选择下发运营单位",
                content:$('#issuedTips').html(),
                btn:['确定','取消'],
                skin:'issuedTips2',
                yes:function(){
                    if(wxb.orgFun.d.hasCk.length>0){
                        var _v1=$('textarea[name="replyClaim"]').val();
                        if(_v1.replace(/\s/g,'')=='') return layer.msg('请填写应对要求');
                        layer.close(ly);
                        wxbData.releaseSub({id:id,downsSet:JSON.stringify(wxb.orgFun.d.hasCk),replyClaim:_v1},type,function(){
                            layer.msg('下发成功');
                            setTimeout(function(){
                                history.back();
                            },300)
                        });
                    }else{
                        layer.msg('没有选取任何下发运营单位')
                    }
                }
            });
            wxb.orgFun.operators($('.modIssued'));
        },
        toUpdate:function(id,type){
            var od={baseID:id,type:3},_val=wxb.init.e.$('textarea[name="advice"]').val();
            if(_val.replace(/\s/g,'')==''){
                return layer.msg('请填写研判意见')
            }
            od.advice=_val;
            wxbData.updateEventRisk(type,od,function(){
                setTimeout(function(){history.back()},500)
            });
        },
        toLook:function(txt){
            layer.open({
                title:'应对情况',
                content:'<div style="text-align: center; width:400px;max-height:500px;overflow-y: auto">'+txt+'</div>',
                btn:!0
            })
        }
    }
};
//安全动态
wxb.dynamicDesc={
    i:function(r){
        wxb.init.com.isOk(function(){
            wxb.dynamicDesc.load(r);
        });
    },
    load:function(r){
        wxb.init.com.menu('index');
        if(r.id){
            wxbData.desc(r.id,function(dr){
                JsTpl('.mod-main').render(dr,'dynamicDesc')
            });
        }else{
            history.back();
        }
    }
};
//组织--运营单位--地方网信办
wxb.orgFun={
    d:{
        hasCk:[]//已选
    },
    com:{
        get:function(){
            var t=this;
            wxb.orgFun.d.orgBox.empty();
            if(wxb.orgFun.d.orgList){
                t.org(wxb.orgFun.d.orgBox,wxb.orgFun.d.orgList);
            }else{
                wxbData.orgList(function(o){
                    wxb.orgFun.d.orgList=o;
                    t.org(wxb.orgFun.d.orgBox,o);
                })
            }
        },
        org:function(b,d,className){
            var ol='';
            className=className||'orgItem';
            $.each(d,function(x,y){
                var cn='';
                $.each(wxb.orgFun.d.hasCk,function(m,n){
                    if(y.orgID==n.orgID){
                        cn='checked';
                        return false
                    }
                });
                ol+='<li class="'+className+'" data-org="'+y.orgID+'"><a href="javascript:;" class="'+cn+'"><i class="fui-font fui-font-check"></i></a><div class="orgItem-bd"><img src="images/abs-org.png">'+y.orgName+'</div></li>'
            });
            b.append(ol);
        },
        opt:function(){
            var t=this;
            if(wxb.orgFun.d.operators){
                t.org(wxb.orgFun.d.orgBox,wxb.orgFun.d.operators,'optItem')
            }else{
                wxbData.Operators(function(r){
                    wxb.orgFun.d.operators=r;
                    t.org(wxb.orgFun.d.orgBox,wxb.orgFun.d.operators,'optItem')
                })
            }
        },
        off:function(){
            var t=this;
            if(wxb.orgFun.d.offices){
                t.org(wxb.orgFun.d.placeBox,wxb.orgFun.d.offices,'optItem')
            }else{
                wxbData.Offices(function(r){
                    wxb.orgFun.d.offices=r;
                    t.org(wxb.orgFun.d.placeBox,wxb.orgFun.d.offices,'optItem')
                })
            }
            if(wxb.orgFun.d.safeList){
                t.org(wxb.orgFun.d.safeBox,wxb.orgFun.d.safeList,'safeItem')
            }else{
                wxbData.safeList(function(r){
                    wxb.orgFun.d.safeList=r;
                    t.org(wxb.orgFun.d.safeBox,wxb.orgFun.d.safeList,'safeItem')
                })
            }
        }
    },
    init:function(box,ck){
        wxb.orgFun.d.orgBox=box.find('.orgList');
        wxb.orgFun.d.hasCk=ck||[];
        wxb.orgFun.com.get();
    },
    operators:function(box){
        wxb.orgFun.d.orgBox=box.find('.placeList');
        wxb.orgFun.d.hasCk=[];
        wxb.orgFun.com.opt();
    },
    offices:function(box){
        wxb.orgFun.d.placeBox=box.find('.placeList');
        wxb.orgFun.d.safeBox =box.find('.safeList');
        wxb.orgFun.d.hasCk=[];
        wxb.orgFun.d.hasCk2=[];
        wxb.orgFun.com.off();
    },
    btn:function(){
        var $=wxb.init.e.$,body=$('body');
        body.on('click','.orgItem',function(){
            var ta=$(this),_t=ta.find('a'),orgID=ta.data('org');
            var nj={orgID:orgID,orgName:ta.find('.orgItem-bd').text()};
            if(_t.hasClass('checked')){
                _t.removeClass('checked');
                var na=[];
                $.each(wxb.orgFun.d.hasCk,function(x,y){
                    if(y['orgID']!=orgID){
                        na.push(y)
                    }
                });
                wxb.orgFun.d.hasCk=na;
            }else{
                _t.addClass('checked');
                var nb=[];
                $.each(wxb.orgFun.d.hasCk,function(x,y){
                    if(y['orgID']!=orgID){
                        nb.push(y)
                    }
                });
                wxb.orgFun.d.hasCk=nb;
                wxb.orgFun.d.hasCk.push(nj);
            }
        });
        body.on('click','.optItem',function(){
            var ta=$(this),_t=ta.find('a'),orgID=ta.data('org');
            if(_t.hasClass('checked')){
                _t.removeClass('checked');
                var na=[];
                $.each(wxb.orgFun.d.hasCk,function(x,y){
                    if(y!=orgID){
                        na.push(y)
                    }
                });
                wxb.orgFun.d.hasCk=na;
            }else{
                _t.addClass('checked');
                var nb=[];
                $.each(wxb.orgFun.d.hasCk,function(x,y){
                    if(y!=orgID){
                        nb.push(y)
                    }
                });
                wxb.orgFun.d.hasCk=nb;
                wxb.orgFun.d.hasCk.push(orgID);
            }
        });
        body.on('click','.safeItem',function(){
            var ta=$(this),_t=ta.find('a'),orgID=ta.data('org');
            if(_t.hasClass('checked')){
                _t.removeClass('checked');
                var na=[];
                $.each(wxb.orgFun.d.hasCk2,function(x,y){
                    if(y!=orgID){
                        na.push(y)
                    }
                });
                wxb.orgFun.d.hasCk2=na;
            }else{
                _t.addClass('checked');
                var nb=[];
                $.each(wxb.orgFun.d.hasCk2,function(x,y){
                    if(y!=orgID){
                        nb.push(y)
                    }
                });
                wxb.orgFun.d.hasCk2=nb;
                wxb.orgFun.d.hasCk2.push(orgID);
            }
        });
        body.on('click','.mi-nav li',function(){
            var _t=$(this),idx=_t.index();
            if(!_t.hasClass('active')){
                _t.addClass('active').siblings().removeClass('active');
                $('.mi-bd-con').eq(idx).show().siblings().hide()
            }
        });
    }
};

//首页-事件/预警快照
wxb.snapshot={
    d:{
        sxData:{}
    },
    i:function(r){
        wxb.init.com.isOk(function(){
            wxb.snapshot.load(r);
        })
    },
    com:function(type,level){
        switch (type){
            case '2':
                wxb.snapshot.d.sxData={
                    page:1,
                    status:1,
                    warningLevel:level
                };
                break;
            case '3':
                wxb.snapshot.d.sxData={
                    page:1,//分页
                    status:1,
                    eventLevel:level
                };
                break;
        }
        this.toList(type);
    },
    toList:function(type){
        var d=wxb.snapshot.d.sxData;
        wxbData.getEventRisk(type,d,function(r){
            listData(r,r['current']);
            JsPage('.ib-page[data-page="managePage"]').render(r['total'],r['current'],function(ck){
                d.page=ck;
                wxbData.getEventRisk(type,d,function(cr){
                    listData(cr,ck);
                })
            });
        });
        var listData=function(dr,page){
            var item=type==2?'risk-item-1':'event-item-1';
            JsTpl('[data-list="manageList"]').render(dr,item,page);
        }
    },
    load:function(r){
        wxb.init.com.menu('index');
        var $= wxb.init.e.$;
        $('.mod-main').empty().append($('#snapshot').html());
        this.com(r.type,r.level)
    }
};
